package com.wuliu.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.wuliu.common.core.domain.entity.SysAppletUser;
import com.wuliu.common.utils.SecurityUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;

import javax.annotation.Resource;

import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.wuliu.common.annotation.Log;
import com.wuliu.common.core.controller.BaseController;
import com.wuliu.common.core.domain.AjaxResult;
import com.wuliu.common.enums.BusinessType;
import com.wuliu.system.service.ISysAppletUserService;
import com.wuliu.common.utils.poi.ExcelUtil;
import com.wuliu.common.core.page.TableDataInfo;

/**
 * 前端用户Controller
 *
 * @author realue
 * @date 2023-10-22
 */
@Api(tags = {"前端用户控制器"})
@RestController
@RequestMapping("/system/appuser")
public class SysAppletUserController extends BaseController {
    @Resource
    private ISysAppletUserService sysAppletUserService;

    /**
     * 查询前端用户列表
     */
    @ApiOperation(value = "查询")
    @PreAuthorize("@ss.hasPermi('system:appuser:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysAppletUser sysAppletUser) {
        sysAppletUser.setSysAccount(getSysAccount());
        startPage();
        List<SysAppletUser> list = sysAppletUserService.selectSysAppletUserList(sysAppletUser);
        return getDataTable(list);
    }

    /**
     * 导出前端用户列表
     */
    @ApiOperation(value = "导出")
    @PreAuthorize("@ss.hasPermi('system:appuser:export')")
    @Log(title = "前端用户", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysAppletUser sysAppletUser) {
        sysAppletUser.setSysAccount(getSysAccount());
        List<SysAppletUser> list = sysAppletUserService.selectSysAppletUserList(sysAppletUser);
        ExcelUtil<SysAppletUser> util = new ExcelUtil<SysAppletUser>(SysAppletUser.class);
        util.exportExcel(response, list, "前端用户数据");
    }

    /**
     * 获取前端用户详细信息
     */
    @ApiOperation(value = "详细")
    @PreAuthorize("@ss.hasPermi('system:appuser:query')")
    @GetMapping(value = "/{userId}")
    public AjaxResult getInfo(@PathVariable("userId") Long userId) {
        return success(sysAppletUserService.selectSysAppletUserByUserId(userId));
    }

    /**
     * 新增前端用户
     */
    @ApiOperation(value = "新增")
    @PreAuthorize("@ss.hasPermi('system:appuser:add')")
    @Log(title = "前端用户", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody @Validated SysAppletUser sysAppletUser) {
        sysAppletUser.setSysAccount(getSysAccount());
        sysAppletUser.setCreateBy(getUsername());
        sysAppletUser.setPassword(SecurityUtils.encryptPassword(sysAppletUser.getPassword()));
        return toAjax(sysAppletUserService.insertSysAppletUser(sysAppletUser));
    }

    /**
     * 修改前端用户
     */
    @ApiOperation(value = "编辑")
    @PreAuthorize("@ss.hasPermi('system:appuser:edit')")
    @Log(title = "前端用户", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody @Validated SysAppletUser sysAppletUser) {
        sysAppletUser.setUpdateBy(getUsername());
        return toAjax(sysAppletUserService.updateSysAppletUser(sysAppletUser));
    }

    /**
     * 删除前端用户
     */
    @ApiOperation(value = "删除")
    @PreAuthorize("@ss.hasPermi('system:appuser:remove')")
    @Log(title = "前端用户", businessType = BusinessType.DELETE)
    @DeleteMapping("/{userIds}")
    public AjaxResult remove(@PathVariable Long[] userIds) {
        return toAjax(sysAppletUserService.deleteSysAppletUserByUserIds(userIds));
    }
}
